package cn.usian.controller;

import cn.usian.common.R;
import cn.usian.entity.Employee;
import cn.usian.entity.Setmeal;
import cn.usian.entity.SetmealDto;
import cn.usian.service.SetmealService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @RequestMapping("/page")
    public R<Page> page(int page,int pageSize,String name){
        return setmealService.page(page,pageSize,name);
    }
    @PostMapping("status/{status}")
    public R status(@PathVariable("status") Integer status,Long[] ids){
        setmealService.status(status,ids);
        return R.success("修改状态成功");
    }
    @DeleteMapping
    public R delete(Long[] ids){
        setmealService.delete(ids);
        return R.success("删除成功");
    }
    @PostMapping
    public R<String> add(@RequestBody SetmealDto setmealDto, HttpServletRequest request){
        Long id = (Long) request.getSession().getAttribute("employee");
        setmealDto.setCreateTime(LocalDateTime.now());
        setmealDto.setUpdateTime(LocalDateTime.now());
        setmealDto.setCreateUser(id);
        setmealDto.setUpdateUser(id);
        setmealService.add(setmealDto);
        return R.success("添加成功！");
    }

}
